package com.ly.mpayment.persist.service.upproductcode;

import java.io.Serializable;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Service;

import com.ly.mpayment.persist.entity.UpProductCode;
import com.ly.mpayment.persist.hibernate.Page;
import com.ly.mpayment.persist.service.AbstractService;

@Service
public class UpProductCodeServiceImpl extends AbstractService<UpProductCode, Serializable> implements IUpProductCodeService {

	@Override
	public boolean saveUpProduct(UpProductCode code) {
		if(code != null){
			this.saveOrUpdate(code);
			return true;
		}
		return false;
	}

	@Override
	public boolean updateUpProduct(UpProductCode code) {
		if(code != null){
			this.saveOrUpdate(code);
			return true;
		}
		return false;
	}

	@Override
	public UpProductCode findById(String id) {
		return findUnique("select u from UpProductCode u where u.proCodeId = ? ", id);
	}

	@Override
	public Page<UpProductCode> findPage(Map<String, Object> parameters, int start, int pageSize) {
		return this.findPageByNamed("select u from UpProductCode u where 1 = 1 #[ and u.productCode like :productCode]# #[ and u.codeName = :codeName]#", parameters, start, pageSize);
	}

	@Override
	public UpProductCode findByCode(String code) {
		return findUnique("select u from UpProductCode u where u.productCode = ? ", code);
	}

	@Override
	public List<UpProductCode> findList() {
		return this.find("select u from UpProductCode u where u.codeStatus = 1 order by u.codeName");
	}

}
